//
//  RechargeWaySelectViewController.m
//  PlayBall
//
//  Created by Edward Zhang on 12-5-9.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "JddRechargeWaySelectViewController.h"
#import "JddCommonFunction.h"
#import "JddViewControllerManager.h"
#import "AppDelegate.h"
#import "JddLoginViewController.h"
@interface JddRechargeWaySelectViewController ()

@end

@implementation JddRechargeWaySelectViewController

SHARED_VIEW_CONTROLLER_IMPLEMENT(JddRechargeWaySelectViewController);

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if(indexPath.row == 0){
        [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_ALIPAY_RECHARGE
                                                             fromController:self
                                                                 withObject:nil
                                                                withObject2:nil];
    }else if (indexPath.row == 1){
        [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_UM_RECHARGE
                                                             fromController:self
                                                                 withObject:nil
                                                                withObject2:nil];
    }
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 85.0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    AppDelegate *appdelegate = [UIApplication sharedApplication].delegate;
    if ([appdelegate.moneyNum isEqualToString:@"100"] || [appdelegate.moneyNum isEqualToString:@"1000"]) {
        return 1;
    }else{
    return 2;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = nil;
    if(indexPath.row == 0){
        cell = [JddRechargeItemAlipayCell getInstanceView];
    }else if (indexPath.row == 1){
        cell = [JddUmRechargeCell getInstanceView];
        
    }
    return cell;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
   // [self.navigationItem setTitle:PAGE_RECHARGE];
    
        UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 40, 30)];
        customLab.backgroundColor = [UIColor clearColor];
        [customLab setText:PAGE_RECHARGE];
        customLab.textAlignment = NSTextAlignmentCenter;

        [customLab setTextColor:[UIColor whiteColor]];
        customLab.font = [UIFont systemFontOfSize:19];
        self.navigationItem.titleView = customLab;
        
        //self.navigationItem.hidesBackButton = YES;
    UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,0)];
    self.tableView.tableFooterView = v;
    [self.tableView setSeparatorColor:SeparatorLineColor];
    if (IOS7) {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
    }
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"ChongZhiFangShi"];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"ChongZhiFangShi"];
    [MobClick event:@"UserCenter-ChongZhiFangShi"];
    [self.tableView reloadData];

    if (([JddCommonFunction isLogin])) {
        
    }else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
                                                        message:@"您还没有登录，请先登录"
                                                       delegate:self
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:@"取消",nil ];
        [alert show];
    }
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if ([alertView.message isEqualToString:@"您还没有登录，请先登录"]) {
        if (buttonIndex==0) {
            [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_LOGIN
                                                                    fromController:self
                                                                        withObject:nil
                                                                       withObject2:nil];
            
        }
    }
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
